<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.lang.*,java.sql.*,javax.naming.*,javax.sql.*"%>
<%@ page import="service.*,java.math.BigDecimal,db.*;"%>
<%
String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ request.getContextPath()+"/";
 %>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>无标题文档</title>
<link rel="stylesheet" type="text/css" href="css/manhuaDialog.1.0.css">
<script type="text/javascript" src="<%=basePath%>js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/lhgdialog.min.js?skin=igreen"></script>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}

.STYLE1 {
	font-size: 12px
}

.STYLE4 {
	font-size: 12px;
	color: #1F4A65;
	font-weight: bold;
}

a:link {
	font-size: 12px;
	color: #06482a;
	text-decoration: none;
}

a:visited {
	font-size: 12px;
	color: #06482a;
	text-decoration: none;
}

a:hover {
	font-size: 12px;
	color: #FF0000;
	text-decoration: underline;
}

a:active {
	font-size: 12px;
	color: #FF0000;
	text-decoration: none;
}

.STYLE7 {
	font-size: 12
}
-->
</style>
<script type="text/javascript">

$(document).ready(function(){
	$("#change").click(function(){
		var ids = $(".adminId:checked");
		if(ids==null || ids.length < 1){
			alert("请选择你要修改的管理员");
			return;
		}else if(ids.length > 1){
			alert("请只选择一个你要修改的管理员");
			return;
		}
		var id = $(".adminId:checked").val();
	 	$.dialog({
				title : '修改管理员信息',
				lock : true,
				content : 'url:manageAdmin.jsp?adminId='+id,
				max : false,
				min : false
		});
	});
	
	var selectAll=  true;
	$("#chooseAll").click(function(){
		//var checkBoxes = $(".adminId");
		$(".adminId").each(function(){
			$(this).attr("checked", selectAll);
		});
		selectAll=!selectAll;
/* 		for(var i = 0; i < checkBoxes.length; i++){
			checkBoxes[i].attr("checked", $("#chooseAll").attr("checked"));
		} */
	});
	$("#creat").click(function(){
	 	$.dialog({
				title : '添加管理员',
				lock : true,
				content : 'url:manageAdmin.jsp?adminId=0',
				max : false,
				min : false
		});
	});
	$("#delete").click(function(){
		var ids = $(".adminId:checked");
		if(ids==null || ids.length < 1){
			alert("请选择你要删除的管理员");
			return;
		}
		var idStr = "";
		var isFirst = true;
		for(var i = 0; i < ids.length; i++){
			if(!isFirst){
				idStr = idStr + ",";
			}else{
				isFirst = false;
			}
			idStr = idStr + ids[i].value;
		}
		$.ajax({
			type : "POST",
			url : "../../servlet/ManageAdminServlet",
			data: "action=delete&idStr="+idStr,
			success : function(result) {
				if(result=="success"){
					window.parent.location.reload(true);
					alert("删除成功！！！");			
				}
			}
		});
	});

});
</script>

</head>

<%
	Connection con = null;
	Statement stmt = null;
	ResultSet rs = null;
	int pageSize, rowCount = 0, pageCount, curPage;
	pageSize = 5;
	pageCount = 1;
	String strPage = request.getParameter("page");
	if (strPage == null)
		curPage = 1;
	else {
		curPage = Integer.parseInt(strPage);//通过参数来定当前页面 
		if (curPage < 1)
			curPage = 1;
	}
%>
<%
	try {
		con = DBConn.getConn();
		stmt = con.createStatement();
		String sql = "select * from shop_admin ,shop_admingroup where shop_admin.admin_groupId = shop_admingroup.admin_group_id ";
		rs = stmt.executeQuery(sql);
		rs.last();
		rowCount = rs.getRow();
		pageCount = (rowCount + pageSize - 1) / pageSize;
		if (curPage > pageCount)
			curPage = pageCount;
	} catch (SQLException e) {
		System.out.println(e.toString());
	}
%>

<body>
<form id="adminForm" name="adminForm" action="<%=basePath%>/servlet/CheckServlet" method="post">
	<table width="100%" border="0" align="center" cellpadding="0"
		cellspacing="0">
		<tr>
			<td height="30"><table width="100%" border="0" cellspacing="0"
					cellpadding="0">
					<tr>
						<td width="15" height="30"><img src="images/tab_03.gif"
							width="15" height="30" /></td>
						<td width="1001" background="images/tab_05.gif"><img
							src="images/311.gif" width="16" height="16" /> <span
							class="STYLE4"> 管理员列表</span></td>
						<td width="200" background="images/tab_05.gif"><table
								border="0" align="right" cellpadding="0" cellspacing="0">
								<tr>
									<td width="60"><table width="87%" border="0"
											cellpadding="0" cellspacing="0">
											<tr>
												<td class="STYLE1"><div align="center">
														<input type="checkbox" name="checkbox62" id="chooseAll" value="checkbox" />
													</div></td>
												<td class="STYLE1"><div align="center">全选</div></td>
											</tr>
										</table></td>

									<td width="60"><table width="90%" border="0"
											cellpadding="0" cellspacing="0">
											<tr>
												<td class="STYLE1"><div align="center">
														<img src="images/001.gif" width="14" height="14" />
													</div>
												</td>
												<td class="STYLE1"><div align="center"><a href="javascript:void(0)" id="creat">新增</a></div>
												</td>
											</tr>
										</table>
									</td>

									<td width="60"><table width="90%" border="0"
											cellpadding="0" cellspacing="0">
											<tr>
												<td class="STYLE1"><div align="center">
														<img src="images/114.gif" width="14" height="14" />
													</div></td>
												<td class="STYLE1"><div align="center">
														<a href="javascript:void(0)" id="change">修改</a>
													</div></td>
											</tr>
										</table></td>

									<td width="60"><table width="88%" border="0"
											cellpadding="0" cellspacing="0">
											<tr>
												<td class="STYLE1"><div align="center">
														<img src="images/083.gif" width="14" height="14" />
													</div>
												</td>
												<td class="STYLE1"><div align="center">
												<a href="javascript:void(0)" id="delete">删除</a></div>
												</td>
											</tr>
										</table>
									</td>
								</tr>
							</table></td>
						<td width="14"><img src="images/tab_07.gif" width="14"
							height="30" /></td>
					</tr>
				</table></td>
		</tr>
		<tr>
			<td><table width="100%" border="0" cellspacing="0"
					cellpadding="0">
					<tr>
						<td width="9" background="images/tab_12.gif">&nbsp;</td>
						<td bgcolor="#f3ffe3"><table width="99%" border="0"
								align="center" cellpadding="0" cellspacing="1" bgcolor="#c0de98">
								<tr>
									<td width="5%" height="18" background="images/tab_14.gif"
										class="STYLE1"><br> <br>
									</td>
									<td width="17%" height="18" background="images/tab_14.gif"
										class="STYLE1"><div align="center" class="STYLE2 STYLE1">管理员名称</div>
									</td>
									<td width="15%" height="18" background="images/tab_14.gif"
										class="STYLE1"><div align="center" class="STYLE2 STYLE1">电子邮件</div>
									</td>
									<td width="15%" height="18" background="images/tab_14.gif"
										class="STYLE1"><div align="center" class="STYLE2 STYLE1">电话</div>
									</td>
									<td width="10%" height="18" background="images/tab_14.gif"
										class="STYLE1"><div align="center" class="STYLE2 STYLE1">管理类别</div>
									</td>
									<td width="30%" height="18" background="images/tab_14.gif"
										class="STYLE1"><div align="center" class="STYLE2 STYLE1">上次登录时间</div>
									</td>
									<td width="8%" height="10" background="images/tab_14.gif"
										class="STYLE1"><div align="center" class="STYLE2">登录次数</div>
									</td>

								</tr>

								<%
									if (pageCount > 0)
										rs.absolute((curPage - 1) * pageSize + 1);
									int i = 0;
									while (i < pageSize && !rs.isAfterLast()) {
								%>
								<tr>
									<td height="18" bgcolor="#FFFFFF"><div align="center"
											class="STYLE1">
											<input  name="adminId" type="checkbox" class="adminId STYLE2"
												value="<%=rs.getInt("admin_id")%>" />
										</div></td>
									<td height="18" bgcolor="#FFFFFF" class="STYLE2"><div
											align="center" class="STYLE2 STYLE1"><%=rs.getString("admin_name")%></div>
									</td>
									<td height="18" bgcolor="#FFFFFF"><div align="center"
											class="STYLE2 STYLE1"><%=rs.getString("admin_email")%></div>
									</td>
									<td height="18" bgcolor="#FFFFFF"><div align="center"
											class="STYLE2 STYLE1"><%=rs.getString("admin_tel")%></div></td>
									<td height="18" bgcolor="#FFFFFF"><div align="center">
											<span class="STYLE2 STYLE1"><%=rs.getString("group_name")%>
											</span>
										</div></td>
									<td height="18" bgcolor="#FFFFFF"><div align="center"
											class="STYLE2 STYLE1"><%=rs.getDate("admin_lastLogin")%>
										</div></td>
									<td height="18" bgcolor="#FFFFFF"><div align="center"
											class="STYLE2 STYLE1"><%=rs.getInt("admin_logins")%>
										</div>
									</td>


								</tr>
								<%
									rs.next();
										i++;
									}
								%>

							</table></td>
						<td width="9" background="images/tab_16.gif">&nbsp;</td>
					</tr>
				</table></td>
		</tr>
		<tr>
			<td height="29"><table width="100%" border="0" cellspacing="0"
					cellpadding="0">
					<tr>
						<td width="15" height="29"><img src="images/tab_20.gif"
							width="15" height="29" /></td>
						<td background="images/tab_21.gif"><table width="100%"
								border="0" cellspacing="0" cellpadding="0">
								<tr>
									<td width="25%" height="29" nowrap="nowrap"><span
										class="STYLE1">共<%=rowCount%>条纪录，当前第<%=curPage%>/<%=pageCount%>页，每页<%=pageSize%>条纪录</span>
									</td>
									<td width="75%" valign="top" class="STYLE1"><div
											align="right">
											<table width="352" height="20" border="0" cellpadding="0"
												cellspacing="0">
												<tr>
													<td width="62" height="22" valign="middle"><div
															align="right">
															<a href="?page=<%=1%>"> <img src="images/first.gif"
																border="0" width="37" height="15" /> </a>
														</div></td>
													<%
														if (curPage > 1) {
													%>
													<td width="50" height="22" valign="middle"><div
															align="right">
															<a href="?page=<%=curPage - 1%>"> <img
																src="images/back.gif" border="0" width="43" height="15" />
															</a>
														</div></td>
													<%
														}
													%>
													<%
														if (curPage < pageCount) {
													%>
													<td width="54" height="22" valign="middle"><div
															align="right">
															<a href="?page=<%=curPage + 1%>"> <img
																src="images/next.gif" border="0" width="43" height="15" />
															</a>
														</div></td>
													<%
														}
													%>
													<td width="49" height="22" valign="middle"><div
															align="right">
															<a href="?page=<%=pageCount%>"> <img
																src="images/last.gif" border="0" width="37" height="15" />
															</a>
														</div></td>
													<td width="59" height="22" valign="middle"><div
															align="right">转到第</div></td>
													<td width="25" height="22" valign="middle"><span
														class="STYLE7"> <input id="pageNum"
															name="textfield" type="text" class="STYLE1"
															style="height:18px; width:25px;" size="5" /> </span></td>
													<td width="23" height="22" valign="middle">页</td>
													<td width="30" height="22" valign="middle"><a
														onclick="tiaozhuan()" style="cursor: pointer;"> <img
															src="images/go.gif" width="37" height="15" /> </a></td>
												</tr>
											</table>
										</div></td>
								</tr>
							</table></td>
						<td width="14"><img src="images/tab_22.gif" width="14"
							height="29" /></td>
					</tr>
				</table></td>
		</tr>
	</table>
</form>
	<%
		rs.close();
		con.close();
	%>
	<script type="text/javascript">
		function tiaozhuan() {
			var value = document.getElementById("pageNum").value;
			if (isNum(value)) {
				document.location = "tab.jsp?page=" + value;
			} else
				alert("请输入正整数！");
		}

		function isNum(num) {
			var reNum = /^\d*$/;
			return (reNum.test(num));
		}
	</script>
</body>
</html>
